package 贪心算法;

public class 柠檬水找零 {
    static class Solution{
        int cash_5 = 0;
        int cash_10 = 0;
        public boolean isEnough(int[] money){
            for (int aMoney : money) {
                if (aMoney == 5) {
                    cash_5++;
                } else if (aMoney == 10) {
                    cash_5--;
                    cash_10++;
                } else if (aMoney == 20) {
                    if (cash_10 > 0) {
                        cash_10--;
                        cash_5--;
                    } else {
                        cash_5 -= 3;
                    }
                }
                if (cash_5 < 0 || cash_10 < 0) return false;

            }
            return true;
        }

    }
}
